<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
/**
 * @property int $id 
 * @property int $platform 
 * @property int $subject_id 
 * @property int $coin 
 * @property string $rmb 
 * @property string $subject_name 
 * @property string $extra 
 * @property int $send 
 * @property int $flag 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class RechargeConfig extends Model
{
    protected const PLATFORM = ['apple' => 1, 'android' => 2];

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'recharge_config';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'platform' => 'integer', 'subject_id' => 'integer', 'coin' => 'integer', 'send' => 'integer', 'flag' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    /**
     * 获取苹果充值配置
     * @return array
     */
    public static function getAndroidRecharge(){
        $data = self::where('platform', self::PLATFORM['android'])->where('flag',1)->orderBy('coin')->get();

        if (empty($data))
        {
            return [];
        }
        
        return $data->toArray();
    }

    /**
     * 获取安卓充值配置
     * @return array
     */
    public static function getAppleRecharge(){
        $data = self::where('platform', self::PLATFORM['apple'])->where('flag',1)->orderBy('coin')->get();

        if (empty($data))
        {
            return [];
        }

        return $data->toArray();
    }
}